/**
 * Created by zg
 */
requirejs.config({
    //基础路径
    baseUrl: "/app/js",
    paths: {
        jquery: "/app/lib/jquery/jquery.min",
        layer : "/app/lib/layer/layer",
        laydate:"/app/lib/laydate/laydate",
        bootstrap: "/app/lib/bootstrap/bootstrap.min",
        angular: "/app/lib/angular/angular",
        ngSanitize: "/app/lib/angular/angular-sanitize.min",
        ngResource: "/app/lib/angular/angular-resource",
        ngUiRouter: "/app/lib/angular/angular-ui-router.min",
        ngAnimate: "/app/lib/angular/angular-animate.min",
        ngUI:"/app/lib/ui-bootstrap-tpls-1.0.3.min",
        echarts:"/app/lib/echarts/echarts",
        d3Test:"/app/lib/js/d3-test",
        superSlide:'/app/lib/jquery/jquery.SuperSlide.2.1.1',
        ueditor:"/app/lib/ueditor/ueditor.all.min",
        ueditorConfig:"/app/lib/ueditor/ueditor.config",
        ueKityFormulaDialog:"/app/lib/ueditor/kityformula-plugin/addKityFormulaDialog",
        ueKfContent:"/app/lib/ueditor/kityformula-plugin/getKfContent",
        ueDefaultFilterFix:"/app/lib/ueditor/kityformula-plugin/defaultFilterFix",
        ueImageDialog:"/app/lib/ueditor/image-plugin/imageDialog",
        ueLang:"/app/lib/ueditor/lang/zh-cn/zh-cn",
        fileinput:"/app/lib/fileinput",
        fileinputLocaleZh:"/app/lib/fileinput_locale_zh",
        baguetteBox:"/app/lib/baguetteBox.min",
        //程序入口
        main: "services/common/main"
    },
    shim: {
        bootstrap: {
            deps: ['jquery'],
            exports: 'bootstrap'
        },
        layer : {
            deps : ['jquery'],
            exports: 'layer'
        },
        angular: {
            deps: ['jquery'],
            exports: 'angular',
            init : function(){
                var _module = angular.module;
                angular.module = function () {
                    var newModule = _module.apply( angular , arguments );
                    if ( arguments.length >= 2 ) {
                        newModule.config([
                            '$controllerProvider' ,
                            '$compileProvider' ,
                            '$filterProvider' ,
                            '$provide' ,
                            '$sceDelegateProvider',
                            function ( $controllerProvider , $compileProvider , $filterProvider , $provide,$sceDelegateProvider ) {
                                $sceDelegateProvider.resourceUrlWhitelist([
                                    // Allow same origin resource loads.
                                    //I have configured $sceDelegateProvider to allow the domain of the api like so:允许的访问路径
                                    'self',
                                    // Allow loading from our assets domain.  Notice the difference between * and **.
                                    'http://*.angular.com/**'
                                ]);
                                //$sceDelegateProvider.resourceUrlWhitelist(["http://downloadres.qlteacher.com/*"]);
                                newModule.controller = function () {
                                    $controllerProvider.register.apply( this , arguments );
                                    return this;
                                };
                                newModule.directive = function () {
                                    $compileProvider.directive.apply( this , arguments );
                                    return this;
                                };
                                newModule.filter = function () {
                                    $filterProvider.register.apply( this , arguments );
                                    return this;
                                };
                                newModule.factory = function () {
                                    $provide.factory.apply( this , arguments );
                                    return this;
                                };
                                newModule.service = function () {
                                    $provide.service.apply( this , arguments );
                                    return this;
                                };
                                newModule.provider = function () {
                                    $provide.provider.apply( this , arguments );
                                    return this;
                                };
                                newModule.value = function () {
                                    $provide.value.apply( this , arguments );
                                    return this;
                                };
                                newModule.constant = function () {
                                    $provide.constant.apply( this , arguments );
                                    return this;
                                };
                                newModule.decorator = function () {
                                    $provide.decorator.apply( this , arguments );
                                    return this;
                                };
                            }
                        ] );
                    }
                    return newModule;
                };

                return angular;
            }
        },
        ngSanitize: {
            deps: ['angular'],
            exports: 'ngSanitize'
        },
        ngResource: {
            deps: ['angular'],
            exports: 'ngResource'
        },
        ngUiRouter: {
            deps: ['angular'],
            exports: 'ngUiRouter'
        },
        ngUI: {
            deps: ['angular'],
            exports: 'ngUI'
        },
        ngAnimate: {
            deps: ['angular'],
            exports: 'ngAnimate'
        },
        superSlide: {
            deps: ['jquery'],
            exports: 'superSlide'
        },
        echarts: {
            deps: ['jquery'],
            exports: 'echarts'
        },
        d3Test: {
            deps: ['jquery'],
            exports: 'd3Test'
        },
        ueditor: {
            deps: ['jquery','ueditorConfig'],
            exports: 'ueditor'
        },
        ueKityFormulaDialog:{
            deps:['ueditorConfig','ueditor'],
            exports:'ueKityFormulaDialog'
        },
        ueKfContent:{
            deps:['ueditorConfig','ueditor'],
            exports:'ueKfContent'
        },
        ueDefaultFilterFix:{
            deps:['ueditorConfig','ueditor'],
            exports:'ueDefaultFilterFix'
        },
        ueImageDialog:{
            deps:['ueditorConfig','ueditor'],
            exports:'ueImageDialog'
        },
        ueLang:{
            deps:['ueditorConfig','ueditor'],
            exports:'ueLang'
        },
        webuploader:{
            deps:['jquery'],
            exports:'webuploader'
        },
        diyUpload:{
            deps:['webuploader'],
            exports:'diyUpload'
        },
        fileinput:{
            deps:['jquery'],
            exports:'fileinput'
        },
        fileinputLocaleZh:{
            deps:['fileinput'],
            exports:'fileinputLocaleZh'
        }
    }
});


/**
 * service模块
 */
define('app.services', ['angular',"ngResource"], function (angular) {
    'use strict';
    return angular.module('app.services',["ngResource"]);
});

/**
 * controllers 模块
 */
define('app.controllers',['angular'],function(angular){
    'use strict';
    return angular.module('app.controllers',[]);
});

/**
 * directives 模块
 */
define('app.directives',['angular'],function(angular){
    'use strict';
    return angular.module('app.directives',['ng','app.services']);
});

/**
 * filter 指令
 */
define('app.filters',['angular'],function(angular){
    'use strict';
    return angular.module('app.filters',[]);
});



/**
 * app模块
 */
define('app', ['angular','ngUiRouter','app.services','app.controllers','app.directives','app.filters','ngUI','bootstrap','ngAnimate'], function (angular) {
    'use strict';
    return angular.module('app', ['ui.router','app.services','app.controllers','app.directives','app.filters','ui.bootstrap','ngAnimate']);
});

/**
 * 页面启动
 */
requirejs(['angular','main'], function (angular,main) {
    'use strict';
    //启动
    var serviceInjector = angular.injector(['ng','app.services']);

    serviceInjector.invoke(['Main',function(service){
        service.start();
    }]);
});